<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/4
 * Time: 18:31
 */
class Activityinfo_con extends Lxbase {
    public $db;
	public $vqurl;
    /*定义各种模块的信息
     * */
    public $arr=array(
        '幸运大转盘' =>array(funname=>'Lottery',table=>'tp_lottery',type=>'1',sub=>'1',pic=>'starpicurl'),
        '水果机' =>array(funname=>'LuckyFruit',table=>'tp_lottery',type=>'4',sub=>'1',pic=>'starpicurl'),
        '一战到底' =>array(funname=>'Problem',table=>'tp_problem_game',sub=>'0',pic=>'logo_pic'),
        '九宫格' =>array(funname=>'Jiugong',table=>'tp_lottery',type=>'10',sub=>'1',pic=>'starpicurl'),
        '摁死小情侣' =>array(funname=>'Lovers',table=>'tp_lottery',type=>'8',sub=>'1',pic=>'starpicurl'),
        '人气冲榜' =>array(funname=>'Popularity',table=>'tp_popularity',sub=>'1',pic=>'pic'),
        '砸金蛋' =>array(funname=>'GoldenEgg',table=>'tp_lottery',type=>'5',sub=>'1',pic=>'starpicurl'),
        '吃月饼大赛' =>array(funname=>'Autumn',table=>'tp_lottery',type=>'9',sub=>'1',pic=>'starpicurl'),
        '七夕走鹊桥' =>array(funname=>'AppleGame',table=>'tp_lottery',type=>'7',sub=>'1',pic=>'starpicurl'),
        '拆礼盒' =>array(funname=>'Autumns',table=>'tp_activity',type=>'1',sub=>'1',pic=>'starpicurl'),
        '分享助力' =>array(funname=>'Helping',table=>'tp_helping',sub=>'1',pic=>'reply_pic'),
        '微场景' =>array(funname=>'Live',table=>'tp_live',sub=>'1',pic=>'open_pic'),
        '微预约' =>array(funname=>'Custom',table=>'tp_custom_set',sub=>'1',pic=>'top_pic'),
        '微调研' =>array(funname=>'Research',table=>'tp_research',sub=>'1',pic=>'logourl'),
        '投票' =>array(funname=>'Vote',table=>'tp_vote',sub=>'1',pic=>'picurl'),
        '图文投票'=>array(funname=>'Voteimg',table=>'tp_voteimg',sub=>'1',pic=>'reply_pic'),
        '外卖'=>array(funname=>'DishOut',table=>'tp_dishout_manage',sub=>'1',pic=>'picurl'),
        '餐饮'=>array(funname=>'Repast',table=>'tp_reply_info',sub=>'1',pic=>'picurl',infotype=>'Dining'),
//        '酒店'=>array(funname=>'Hotels',table=>'tp_reply_info',sub=>'1',pic=>'picurl'),
        '全景'=>array(funname=>'Panorama',table=>'tp_reply_info',sub=>'1',pic=>'picurl',infotype=>'panorama'),
        '摇一摇'=>array(funname=>'Shake',table=>'tp_shake',sub=>'1',pic=>'thumb'),
        '签到'=>array(funname=>'Fanssign',table=>'tp_sign_set',sub=>'1',pic=>'reply_img'),
        '微信墙'=>array(funname=>'Wall',table=>'tp_wall',sub=>'1',pic=>'background'),
        '微信红包'=>array(funname=>'Red_packet',table=>'tp_red_packet',sub=>'1',pic=>'msg_pic'),
        '刮刮卡'=>array(funname=>'Guajiang',table=>'tp_lottery',type=>'2',sub=>'1',pic=>'starpicurl'),
        '现场活动'=>array(funname=>'Scene_member',table=>'tp_wechat_scene',sub=>'1',pic=>'pic'),
        '教育'=>array(funname=>'School',table=>'tp_school_set_index',sub=>'1',pic=>'head_url'),
        '汽车1'=>array(funname=>'Car',table=>'tp_carset',sub=>'1',pic=>'head_url'),
        '汽车2'=>array(funname=>'Car',table=>'tp_reservation',sub=>'1',pic=>'picurl',addtype=>'maintain'),
        '汽车3'=>array(funname=>'Car',table=>'tp_carowner',sub=>'1',pic=>'head_url'),
        '汽车4'=>array(funname=>'Car',table=>'tp_reservation',sub=>'1',pic=>'picurl',addtype=>'drive'),
        '房产1'=>array(funname=>'Estate',table=>'tp_estate',sub=>'1',pic=>'cover',a=>'set'),
        '房产2'=>array(funname=>'Estate',table=>'tp_reservation',sub=>'1',pic=>'picurl',a=>'reservation',addtype=>'house_book'),
        'KTV'=>array(funname=>'Business',table=>'tp_busines',sub=>'1',pic=>'picurl',type=>'ktv'),
        '美容'=>array(funname=>'Business',table=>'tp_busines',sub=>'1',pic=>'picurl',type=>'beauty'),
        '宠物'=>array(funname=>'Business',table=>'tp_busines',sub=>'1',pic=>'picurl',type=>'affections'),
        '食品'=>array(funname=>'Business',table=>'tp_busines',sub=>'1',pic=>'picurl',type=>'food'),
        '物业'=>array(funname=>'Business',table=>'tp_busines',sub=>'1',pic=>'picurl',type=>'property')
      //  '微论坛' =>array(linkurl=>'http://vq.zhongsou.com/index.php?g=Wap&m=Forum&a=index',sub=>'0'),
      //  '留言板' =>array(linkurl=>"http://vq.zhongsou.com/index.php?g=Wap&m=Reply&a=index",sub=>'0'),
    );

    //41机器数据连接
    public function  returninfo()
    {
        $username = $_REQUEST['username'];
        $keyword = $_REQUEST['keyword'];

		$urlhost = empty($_SERVER["SERVER_NAME"])?$_SERVER["HTTP_HOST"]:$_SERVER["SERVER_NAME"];
		if($urlhost == 'kaifa.zq.zhongsou.com' || $urlhost=='zq.zhongsou.com'){
			$dbconn = array( "host"=>'103.7.222.62', "user"=>'root', "pass"=>'zhs20151117', "name"=>'qiyuedb_new');
			$this->vqurl='http://kaifa.vq.zhongsou.com/';
		}else{
			$dbconn = array( "host"=>'103.7.222.41', "user"=>'b2ctest', "pass"=>'B2@c@2tE8T', "name"=>'qiyuedb');
			$this->vqurl='http://vq.zhongsou.com/';
		}
        $this->db = new Lxdb($dbconn);
        if (empty($username) || empty($keyword)) {
            $datap['status'] = '0';
            $data['info'] = '参数不能为空';
            echo json_encode($data);
            exit;
        } elseif (!($this->db->arrdata('*', 'tp_users',"where username = '$username'"))) {             //用户名是否存在
            $datap['status'] = '0';
            $data['info'] = '用户名不存在';
            echo json_encode($data);
            exit;
        }

        //异常判断后读出数据
        //$result = $this->mongo()->findOne('activityinfo', array('username' => $username, 'keyword' => $keyword));
         $result = false;

        if (!$result) {
            $arrbase = $this->arr;
            $info = array();
            $tokenvalue = $this->db->viewdata("token", 'tp_users',"where username= '$username'");
            $token = $tokenvalue["token"];
            if( $keyword == "留言"){
                $infos = $this->db->arrdata('*', 'tp_reply_info',"where  token = '$token'  ");
                if($infos){
                    array_push($info,array('linkcode'=>$this->vqurl."index.php?g=Wap&m=Reply&a=index&token=".$token ,
                                            'starpicurl'=>  $infos[0]["picurl"],
                                             'info'=>$infos[0]["info"],
                                             'name'=>$info[0]["title"]
                    ));
                }
            }elseif( $keyword=="论坛"  ){
                $infos = $this->db->arrdata('*', 'tp_forum_config',"where  token = '$token'  ");
                if($infos){
                    array_push($info,array('linkcode'=>$this->vqurl."index.php?g=Wap&m=Forum&a=index&token=".$token,
                        'starpicurl'=>  $infos[0]["picurl"],
                        'info'=>$infos[0]["intro"],
                        'name'=>"论坛",
                    ));
                }
            }
            foreach ($arrbase as $key => $item) {
                if (!empty($item['type'])) {
                    $type = $item['type'];
                    $infos = $this->db->arrdata('*', $item['table'],"where  token = '$token' and keyword='$keyword' and type= '$type' ");
                }elseif($item['funname'] =='Fanssign'){
                    $infos = $this->db->arrdata('*', $item['table'],"where  token = '$token' and  keywords='$keyword' ");  //坑呀。。签名表关键字字段与其它活动表这个不一样，为  keywords
                }elseif(!empty($item['infotype'])){
                    $infotype = $item['infotype'];
                    $infos = $this->db->arrdata('*', $item['table'],"where  token = '$token' and keyword='$keyword' and infotype= '$infotype' ");
                }elseif(!empty($item['addtype'])) {
                    $addtype = $item['addtype'];
                    $infos = $this->db->arrdata('*', $item['table'], "where  token = '$token' and keyword='$keyword' and addtype= '$addtype' ");
                } else {
                    $infos = $this->db->arrdata('*', $item['table'],"where  token = '$token' and keyword='$keyword' ");
                }

                if ($infos) {
                    foreach ($infos as $key2 => $items) {
                        $title = $items['title'];
                        $infoitem =  $items['info'];
                        $url= $this->vqurl.'index.php?g=Wap&m=' . $item["funname"] . '&a=index&token=' . $token . '&id=' . $items['id'] ;

                        if(empty( $items[$item['pic']])){
                            $items['starpicurl']="http://qiyue.zhongsou.com/tpl/Wap/default/common/css/guajiang/images/activity-lottery-start.jpg"; //没有图片存放默认图片,暂时随便放的图片
                        }elseif(empty( $items['info'])){
                            $items['info']="亲，本活动暂时没有活动详情介绍，祝您好运哦！";
                        }

                        if($item["funname"] =='Research' ){
                            $url= $this->vqurl.'index.php?g=Wap&m='.$item["funname"].'&a=index&token='.$token.'&reid='.$items['id'] ;  //坑 微调研最后的ID为reid
                        }
                        if($item["funname"] =='Custom'){
							 $items['id'] = $items['set_id'];
                             $infoitem = $items['intro'];
                            $url= $this->vqurl.'index.php?g=Wap&m='.$item["funname"].'&a=index&token='.$token.'&set_id='.$items['set_id'] ;  //坑 微预约数据库里的的ID为setid
                        }
                         if($item["funname"] =='DishOut'){
                             $title= $items['rtitle'];
                             $infoitem = $items['rinfo'];
                             $url= $this->vqurl.'index.php?g=Wap&m='.$item["funname"].'&a=MyShop&token='.$token.'&id='.$items['id'].'&cid='.$items['cid'] ;
                         }
                         if($item['funname']=='Shake'){
                             $url= $this->vqurl.'index.php?g=Wap&m=' . $item["funname"] . '&a=index&token=' . $token . '&id=' . $items['id'].'&act_type=2' ;
                         }
                        if($item['funname']=='Helping'){
                            $infoitem = $items['intro'];
                        }
                        if($item['funname']=='Scene_member'){
                            $url= $this->vqurl.'index.php?g=Wap&m=' . $item["funname"] . '&a=index&token=' . $token . '&id=' . $items['id'].'&act_type=2' ;
                        }
//                        if($item["funname"] == 'Product' && $item["a"] == 'dining'){
//                            $url= $this->vqurl.'index.php?g=Wap&m='.$item["funname"].'&a='.$item["a"].'&token='.$token.'&reid='.$items['id'] ;
//                        }
                        if($item["funname"] == 'Estate' && $item["a"] == 'set'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Estate&a=index&token='.$token.'&id='.$items['id'] ;
                        }
                        if($item["funname"] == 'Estate' && $item["a"] == 'reservation'){
                            $eid = $this->db->viewdata('id','tp_estate','where token = "' . $token . '"')['id'];
                            $url= $this->vqurl.'index.php?g=Wap&m=Reservation&a=index&token='.$token.'&rid='.$items['id'] . '&id=' . $eid;
                        }
                        if($item["funname"] == 'Car' && $item["table"] == 'tp_carset'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Car&a=index&token='.$token.'&id='.$items['id'] ;
                        }
                        if($item["funname"] == 'Car' && $item["table"] == 'tp_reservation' && $item["addtype"] == 'maintain'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Car&a=CarReserveBook&addtype=maintain&token='.$token;
                        }
                        if($item["funname"] == 'Car' && $item["table"] == 'tp_reservation' && $item["addtype"] == 'drive'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Car&a=CarReserveBook&addtype=drive&token='.$token;
                        }
                        if($item["funname"] == 'Car' && $item["table"] == 'tp_carowner'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Car&a=owner&token='.$token;
                        }
                        if($item["funname"] == 'Business' && $item["table"] == 'tp_busines' && $item["type"] == 'ktv'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Business&a=index&type=ktv&token='.$token.'&bid='.$items['bid'];
                        }
                        if($item["funname"] == 'Business' && $item["table"] == 'tp_busines' && $item["type"] == 'beauty'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Business&a=index&type=beauty&token='.$token.'&bid='.$items['bid'];
                        }
                        if($item["funname"] == 'Business' && $item["table"] == 'tp_busines' && $item["type"] == 'affections'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Business&a=index&type=affections&token='.$token.'&bid='.$items['bid'];
                        }
                        if($item["funname"] == 'Business' && $item["table"] == 'tp_busines' && $item["type"] == 'food'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Business&a=index&type=food&token='.$token.'&bid='.$items['bid'];
                        }
                        if($item["funname"] == 'Business' && $item["table"] == 'tp_busines' && $item["type"] == 'property'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Business&a=index&type=property&token='.$token.'&bid='.$items['bid'];
                        }
                        if($item["funname"] == 'Repast' && $item["type"] == 'Dining'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Repast&a=index&token='.$token;
                        }
                        if($item["funname"] == 'Panorama' && $item["type"] == 'panorama'){
                            $url= $this->vqurl.'index.php?g=Wap&m=Panorama&a=index&token='.$token;
                        }
//                        if($item["funname"] == 'Hotels'){
//                            $url= $this->vqurl.'index.php?g=Wap&m=Hotels&a=index&token='.$token;
//                        }
                        array_push($info, array('id' => $items['id'], 'name' => $title, 'linkcode' => $url, 'keyword' => $items['keyword'], 'starpicurl' => $items[$item['pic']], 'info' =>$infoitem));
                    }
                }
            }

            if (!empty($info)) {
                $data['status'] = 1;
                $data['item'] = $info;
                $this->mongo()->insert('activityinfo',array('username'=>$username,'keyword'=>$keyword,'item'=>$data['item']));//存入mogo

            } else {
                $data['status'] = 0;
                $data['item'] = "";//没有内容时置空，不放任何内容
            }
            echo json_encode($data);exit;
        } else {
            echo json_encode($result);exit;
        }
    }




    public  function test(){
        $username = $_REQUEST['username'];
        $keyword = $_REQUEST['keyword'];
        $this->db = new Lxdb($this->dbconn);
        if (empty($username) || empty($keyword)) {
            $datap['status'] = '0';
            $data['info'] = '参数不能为空';
            echo json_encode($data);
            exit;
        } elseif (!($this->db->arrdata('*', 'tp_users',"where username = '$username'"))) {             //用户名是否存在
            $datap['status'] = '0';
            $data['info'] = '用户名不存在';
            echo json_encode($data);
            exit;
        }
        //异常判断后读出数据
        //$result = $this->mongo()->findOne('activityinfo', array('username' => $username, 'keyword' => $keyword));
        $result = false;
        if (!$result) {
            $arrbase = $this->arr;
            $info = array();
            $tokenvalue = $this->db->viewdata("token", 'tp_users',"where username= '$username'");
            $token = $tokenvalue["token"];
            if( $keyword == "留言"){
                $infos = $this->db->arrdata('*', 'tp_reply_info',"where  token = '$token'  ");
                if($infos){
                    array_push($info,array('linkcode'=>$this->vqurl."index.php?g=Wap&m=Reply&a=index&token=".$token ,
                        'starpicurl'=>  $infos[0]["picurl"],
                        'info'=>$infos[0]["info"],
                        'name'=>$info[0]["title"]
                    ));
                }
            }elseif( $keyword=="论坛"  ){
                $infos = $this->db->arrdata('*', 'tp_forum_config',"where  token = '$token'  ");
                if($infos){
                    array_push($info,array('linkcode'=>$this->vqurl."index.php?g=Wap&m=Forum&a=index&token=".$token,
                        'starpicurl'=>  $infos[0]["picurl"],
                        'info'=>$infos[0]["intro"],
                        'name'=>"论坛",
                    ));
                }
            }
            foreach ($arrbase as $key => $item) {
                if (!empty($item['type'])) {
                    $type = $item['type'];
                    $infos = $this->db->arrdata('*', $item['table'],"where  token = '$token' and keyword='$keyword' and type= '$type' ");
                } else {
                    $infos = $this->db->arrdata('*', $item['table'],"where  token = '$token' and keyword='$keyword' ");
                }
                if ($infos) {
                    foreach ($infos as $key2 => $items) {
                        if(empty( $items['starpicurl'])){
                            $items['starpicurl']="http://qiyue.zhongsou.com/tpl/Wap/default/common/css/guajiang/images/activity-lottery-start.jpg"; //没有图片存放默认图片
                        }elseif(empty( $items['infol'])){
                            $items['info']="亲，本活动暂时没有活动详情介绍，祝您好运哦！";
                        }
                        array_push($info, array('id' => $items['id'], 'name' => $items['title'], 'linkcode' => $this->vqurl.'index.php?g=Wap&m=' . $item["funname"] . '&a=index&token=' . $token . '&id=' . $items['id'], 'keyword' => $items['keyword'], 'starpicurl' => $items['starpicurl'], 'info' => $items['info']));
                    }
                }
            }
            if (!empty($info)) {
                $data['status'] = 1;
                $data['item'] = $info;
                $this->mongo()->insert('activityinfo',array('username'=>$username,'keyword'=>$keyword,'item'=>$data['item']));//存入mogo
            } else {
                $data['status'] = 0;
                $data['item'] = "";//没有内容时置空，不放任何内容
            }
            echo json_encode($data);exit;
        } else {
            echo json_encode($result);exit;
        }

    }

}